import CommonBaseSchema from '#common/base_schema'

export default class extends CommonBaseSchema {
  protected tableName = 'card_rights'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()
      table
        .integer('fk_shop_id')
        .notNullable()
        .unsigned()
        .references('shops.id')
        .comment('所属店铺ID')

      table.string('name', 100).unique().comment('名称')
      table.tinyint('discount').unsigned().defaultTo(10).comment('折扣')
      table.integer('store_amount').unsigned().defaultTo(0).comment('储值金额')
      table.integer('gift_amount').unsigned().defaultTo(0).comment('赠送金额')
      table.integer('sale_price').unsigned().defaultTo(0).comment('销售价格')
      table.integer('min_price').unsigned().defaultTo(0).comment('最低价格')
      table.integer('exp_num').unsigned().defaultTo(1).comment('权益数量')
      table.integer('exp_type').unsigned().defaultTo(1).comment('权益类型 1购买时 2消费时')
      table.enum('exp_unit', ['year', 'month', 'day']).comment('权益单位')
      table.tinyint('status').unsigned().defaultTo(1).comment('状态')
      table.string('memo', 255).defaultTo('').comment('备注')

      this.defineCommonColumns(table)
      table.comment('会员权益表')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
